
//
//  BBHomeViewController.m
//  BlockBrowser
//
//  Created by Mac on 2018/3/28.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "BBNewHomeViewController.h"
#import "BBPhoneLoginViewController.h"
#import "KLClearTableHeaderView.h"
#import "BBHomeHeaderView.h"
#import "BBArticleViewController.h"
#import "BBArticleViewController.h"
#import "BBHomeTableViewCell.h"
#import "BBLoginHomeViewController.h"
#import "BBLoginHomeViewController.h"
#import "BBHomeMenuModel.h"
#import "BBArticleModel.h"
#import "BBHomeWebTableViewCell.h"
#import "NSCalendar+STCalendarTool.h"
#import "BBHomeMenuPresentViewController.h"
#import "BBMineViewController.h"
#import "BBGlobalSearchViewController.h"
#import "STLocationManger.h"
#import "BBShareNewsPresentViewController.h"
#import "TMTabbarViewController.h"
#import "BBWebViewController.h"
@interface BBNewHomeViewController ()<BBHomeHeaderViewDelegate>
@property(nonatomic, strong) BBHomeHeaderView                     *header;
@property(nonatomic, strong) BBUserModel                     *userModel;
@property(nonatomic, strong) NSMutableArray <BBHomeMenuModel*>                    *menuArray;
@property(nonatomic, strong) NSMutableArray                     *dataSouce;
@property(nonatomic, assign) NSInteger                    page;/**< 页数 */
@property(nonatomic, strong) STButton                     *numButton;/**< 未读新闻 */
@end

@implementation BBNewHomeViewController
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
- (STButton *)numButton{
    if (!_numButton) {
        _numButton= [[STButton alloc] initWithFrame:CGRectMake(0, 30, 90, 26)
                                                         title:@""
                                                    titleColor:UIColor.whiteColor
                                                     titleFont:13
                                                  cornerRadius:13
                                               backgroundColor:FlatCoffee
                                               backgroundImage:nil
                                                         image:nil];
        _numButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        _numButton.hidden = YES;
        __weak typeof(self) weakSelf =  self;
        [_numButton setClicAction:^(UIButton *sender) {
            sender.hidden = YES;
            [weakSelf.tableView.mj_header beginRefreshing];
        }];
        _numButton.centerX = UIScreenWidth / 2;
    }
    return _numButton;
}
#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
    [self countDownTimerAction];
   // [self sendGetReadAward];
    [BBArticleViewController defult];
    [self configSubView];
    [self.view addSubview:self.numButton];
    [self sendHomeMenuListRequest];
    [self sendHomeArtistListRequest];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [[BBNavHistoryManger manger] autoJudgeAddViewController:self];
    
    [[STLocationManger defult] startUpdatingLocationHande:^(STError *error, CLPlacemark *placemark) {
        if (placemark) {
            [[STLocationManger defult] updatePlacemarkWith:placemark];
            [self sendWhereRequestWithCity:[STLocationManger defult].lastCity];
        }
    }];
     [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
   // [self sendGetReadAward];
    [self st_hideNavagetionbarAnimated:animated];
    [self findUser];
    [self sendHomeArtistListRequest];
    [self sendHomeMenuListRequest];
    [self sendWhereRequestWithCity:[STLocationManger defult].lastCity];
    [[STLocationManger defult] startUpdatingLocationHande:^(STError *error, CLPlacemark *placemark) {
        if (placemark) {
            [[STLocationManger defult] updatePlacemarkWith:placemark];
            [self sendWhereRequestWithCity:[STLocationManger defult].lastCity];
        }
    }];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    TMTabbarViewController * tab = (id)self.tabBarController;
    tab.leftButton.selected = NO;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        BOOL openLast = [[NSUserDefaults standardUserDefaults] boolForKey:openLastKey];
        BOOL diedIsAtHome = [[NSUserDefaults standardUserDefaults] boolForKey:diedIsAtHomeKey];
        if (openLast && !diedIsAtHome) {
            BBScanHistoryModel * model  = [[BBHistoryManger manger] scanArray].lastObject;
            STWebViewController * webvc =  [[STWebViewController alloc] initWithUrl:model.url];
            webvc.forceTitle = model.title;
            webvc.shouldNotRecord = YES;
            [self.navigationController pushViewController:webvc animated:YES];
        }
        
    });
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:diedIsAtHomeKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self st_showNavagationbarAnimated:animated];
    
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    TMTabbarViewController * tab = (id)self.tabBarController;
    tab.leftButton.selected = YES;
}
- (void)findUser{
    [TMUtils sendUserInfoRequest:^(BBUserModel *user) {
        self.userModel = user;
        self.header.searchView.userModel = user;
        if (!user) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                static dispatch_once_t onceToken;
                dispatch_once(&onceToken, ^{
                    [self findUser];
                });
            });
            
        }
    }];
}
#pragma mark --subView
- (void)configSubView{
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.page = 1;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.page = 1;
        [self viewWillAppear:YES];
    }];
    self.tableView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        self.page ++;
        [self sendHomeArtistListRequest];
    }];
    self.view.backgroundColor = [BBThemeColorManger manger].themeColor;
    self.header = [[BBHomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, homeHeaderViewHeight)];
    self.header.delegate = self;
    self.tableView.tableHeaderView = self.header;
    self.tableView.backgroundColor = UIColor.whiteColor;
    self.tableView.height = UIScreenHeight - 20;
    self.tableView.top = 20;
    CGFloat tabbarTop;
    if (KIsiPhoneX) {
        tabbarTop = UIScreenHeight - 83;
    }else{
        tabbarTop = UIScreenHeight - 49;
    }
    UIEdgeInsets inset = UIEdgeInsetsMake(0, 0, (UIScreenHeight -tabbarTop),0);
    self.tableView.contentInset = inset;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count    ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray * array = self.dataSouce[section];
    return array.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    BBArticleModel*model = self.dataSouce[indexPath.section][indexPath.row];
    if (model.isSelcted) {
        if (!model.allHeight) {
            BBHomeTableViewCell * cell = [[BBHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"caclute"];
            cell.model = model;
        }
        return model.allHeight;
    }
    return [BBHomeTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    //  return 0.01;
    return 53;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    BBArticleModel*model = self.dataSouce[section][0];
    NSString * timeFirst = [model.dateline componentsSeparatedByString:@" "].firstObject;
    model.time = timeFirst;
    NSDate * todayDate = [NSDate st_localCurrentDate];
    NSDate * ysetordayDate = [NSCalendar st_lastDayDate:todayDate];
    NSDate * qiantianDate = [NSCalendar st_lastDayDate:ysetordayDate];
    NSString * dayString = @"";
    if ([todayDate.st_yyyyMMddByLineWithDate isEqualToString:model.time]) {
        dayString = @"今天";
    }
    if ([ysetordayDate.st_yyyyMMddByLineWithDate isEqualToString:model.time]) {
        dayString = @"昨天";
    }
    if ([qiantianDate.st_yyyyMMddByLineWithDate isEqualToString:model.time]) {
        dayString = @"前天";
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    [formatter setTimeZone:GTMzone];
    
    NSDate * modelDate = [formatter dateFromString:timeFirst];
    NSString * weekDay =  [NSCalendar st_weekDayWithDate:modelDate];
    
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 53)];
    header.backgroundColor = TM_backgroundColor;

    NSString * title = [NSString stringWithFormat:@"%@%@   %@",dayString,model.time,weekDay];
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30, 53)
                                                     text:title
                                                textColor:SecendTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:titleLable];
    if ([BBThemeColorManger manger].type == BBThemeColorStyleBlacklook) {
        header.backgroundColor = FlatGray;
    }
    return header;
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString * reuseIdentifier =  [NSString stringWithFormat:@"%ld-%ld",indexPath.section,indexPath.row];
    reuseIdentifier = @"cell";
    BBHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[BBHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    BBArticleModel*model = self.dataSouce[indexPath.section][indexPath.row];
    cell.model = model;
    __weak typeof(self) weakSelf =  self;
    [cell.shareButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedShareButtonWithIndexPath:indexPath];
    }];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    

    BBArticleModel*model = self.dataSouce[indexPath.section][indexPath.row];
    model.isSelcted = !model.isSelcted;
    if (!model.allHeight) {
        BBHomeTableViewCell * cell = [[BBHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"caclute"];
        cell.model = model;
    }
    if (model.currentLableHeight <= model.originLableHeight) {
        model.isSelcted = !model.isSelcted;
        return;
    }
    
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];



}
#pragma mark --BBHomeHeaderViewDelegate
- (void)homeHeaderVewSelctedSearchWithTitle:(NSString*)title{
    if ([title isEqualToString:@"用户"]) {
        if (self.userModel) {
            [self gotoMineViewController];
        }else{
            [self.navigationController pushViewController:[BBPhoneLoginViewController new] animated:YES];
        }
    }
    if ([title isEqualToString:@"搜索"]) {
        BBGlobalSearchViewController * vc = [BBGlobalSearchViewController new];
        [vc setDidSelctedSearch:^(NSString *keyword) {
            [self onSelctedSearchWithKeyWord:keyword];
        }];
        STNavigationController * nav = [[STNavigationController alloc] initWithRootViewController:vc];
        
        [self presentViewController:nav animated:YES completion:nil];
    }
    
}
- (void)homeHeaderVewSelctedMenuWithTitle:(NSString*)title{
    BBHomeMenuModel * model  = [self modelFormDataSouceWithTitle:title];
    if (model) {
        if ([model.name isEqualToString:@"挖矿"]) {
            [self gotoMineViewController];
        }else if ([model.name containsString:@"优酷"]){
            BBWebViewController * vc = [BBWebViewController new];
            vc.urlStr = model.url;
            vc.forceTitle = title;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            STWebViewController * vc =   [[STWebViewController alloc] initWithUrl:model.url];
            vc.forceTitle = title;
            vc.progressBackgroundColor = FlatGray;
            vc.progressTintColor = FlatMint;
            [self.navigationController pushViewController:vc animated:YES];
            
//            BBWebViewController * vc = [BBWebViewController new];
//            vc.urlStr = model.url;
//            vc.forceTitle = title;
//            [self.navigationController pushViewController:vc animated:YES];
            
        }
        
    }
    
}
- (BBHomeMenuModel*)modelFormDataSouceWithTitle:(NSString*)title{
    for (BBHomeMenuModel * model in self.menuArray) {
        if ([model.name isEqualToString:title]) {
            return model;
        }
    }
    return nil;
}
#pragma mark --Private Method
- (void)gotoMineViewController{
    BBMineViewController * vc = [BBMineViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}
- (NSArray*)dealArray:(NSArray*)array{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSMutableArray * setsArray = [NSMutableArray new];
    NSMutableArray * finshArray = [NSMutableArray new];
    for (NSInteger i = 0; i < array.count; i ++) {
        BBArticleModel * model = array[i];
        NSString * topDeadLine = [model.dateline componentsSeparatedByString:@" "].firstObject;
        [dic setObject:topDeadLine forKey:topDeadLine];
    }
    NSArray * keysArray = dic.allKeys;
    keysArray = [keysArray sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return [obj2 compare:obj1];
    }];
    for (NSObject * obj in keysArray) {
        NSMutableArray * setionArray = [NSMutableArray new];
        [finshArray addObject:setionArray];
        [setsArray addObject:obj];
    }
    for (NSInteger i = 0; i < array.count; i ++) {
        BBArticleModel * model = array[i];
        NSString * topDeadLine = [model.dateline componentsSeparatedByString:@" "].firstObject;
        NSInteger index = [setsArray indexOfObject:topDeadLine];
        NSMutableArray * existArray =  [finshArray objectAtIndex:index];
        model.time = topDeadLine;
        [existArray addObject:model];
    }
    
    return finshArray;
}
#pragma mark --NetWork Method
- (void)sendHomeMenuListRequest{
    
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",severHeader,@"/api/advert/list"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypeGet
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 NSArray * array = responseObject[@"data"];
                                                 self.menuArray = [NSMutableArray new];
                                                 for (NSDictionary * modelDic in array) {
                                                     BBHomeMenuModel * model = [BBHomeMenuModel mj_objectWithKeyValues:modelDic];
                                                     [self.menuArray addObject:model];
                                                 }
                                                 self.header.menuView.dataSouce = self.menuArray;
                                                 static dispatch_once_t onceToken;
                                                 dispatch_once(&onceToken, ^{
                                                      [self beginNewsCountMonitor];
                                                 });
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
- (void)sendHomeArtistListRequest{
    
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",severHeader,@"/api/news/list"];
    [dic setObject:@(_page) forKey:@"page"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypeGet
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 if (self.page == 1) {
                                                     self.dataSouce= [NSMutableArray new];
                                                 }
                                                
                                                 NSArray * array = responseObject[@"data"][@"list"];
                                                 NSLog(@"%@",array.mj_JSONString);
                                                 NSMutableArray *dataSouce = [NSMutableArray new];
                                                 for (NSDictionary * modelDic in array) {
                                                     BBArticleModel * model = [BBArticleModel mj_objectWithKeyValues:modelDic];
                                                     [dataSouce addObject:model];
                                                 }
                                                 [self.tableView.mj_header endRefreshing];
                                                 [self.tableView.mj_footer endRefreshing];
                                                 NSArray * dealArray = [self dealArray:dataSouce];
                                                 [self.dataSouce addObjectsFromArray:dealArray];
                                                 [self.tableView reloadData];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 
                                                 [self.tableView.mj_header endRefreshing];
                                                 [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
- (void)beginNewsCountMonitor{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",severHeader,@"/api/news/list"];
    [dic setObject:@(1) forKey:@"page"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypeGet
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 NSArray * array = responseObject[@"data"][@"list"];
                                                 NSLog(@"%@",array.mj_JSONString);
                                                 NSMutableArray *dataSouce = [NSMutableArray new];
                                                 NSInteger sum = 0;
                                                 for (NSDictionary * modelDic in array) {
                                                     BBArticleModel * model = [BBArticleModel mj_objectWithKeyValues:modelDic];
                                                     if (![self existModelFormDataSouce:model]) {
                                                         sum = sum + 1;
                                                     }
                                                     [dataSouce addObject:model];
                                                 }
                                                 [self.numButton setTitle:[NSString stringWithFormat:@"%ld 条未读消息",sum] forState:UIControlStateNormal];
                                                 self.numButton.hidden = !sum;
                                                 

                                                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                                     [self beginNewsCountMonitor];
                                                 });
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 
                                                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                                     [self beginNewsCountMonitor];
                                                 });
                                             }];
}
#pragma mark --Private Method
- (BOOL)existModelFormDataSouce:(BBArticleModel*)model{
    for (NSArray * array in self.dataSouce) {
        for (BBArticleModel * existModel in array) {
            if (existModel.newsID.integerValue == model.newsID.integerValue) {
                return YES;
            }
        }
    }
    return NO;
}
#pragma mark --Action Method
- (void)countDownTimerAction{
    for (BBHomeTableViewCell * cell in self.tableView.visibleCells) {
        if (cell.model.canCountDown) {
            NSString * time = [cell.model currentDetailTime];
            [cell.detailTimeButton setTitle:time forState:UIControlStateNormal];
        }

    }
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self countDownTimerAction];
    });
}
- (void)onSelctedSearchWithKeyWord:(NSString*)keyword{
    //    search    "https://www.baidu.com/s?wd="
    //    suggestion    "http://suggestion.baidu.com/su?wd="
    NSString * finsh = [keyword stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    

    NSString * url = [NSString stringWithFormat:@"https://www.baidu.com/s?wd=%@",finsh];
//    if ([keyword containsString:@"http://"] || [keyword containsString:@"https://"]) {
//        url = keyword;
//    }
    if ([finsh isUrl]) {
        if (![finsh containsString:@"http://"]) {
            finsh = [NSString stringWithFormat:@"http://%@",finsh];
        }
        url = finsh;
    }
    
    STWebViewController * vc =   [[STWebViewController alloc] initWithUrl:url];
    vc.forceTitle = keyword;
    if ([finsh isUrl]) {
        vc.forceTitle = @"";
    }
    vc.progressBackgroundColor = FlatGray;
    vc.progressTintColor = FlatMint;
    [self.navigationController pushViewController:vc animated:YES];
    //   [[BBNavHistoryManger manger] autoJudgeAddViewController:vc];
}
- (void)onSelctedShareButtonWithIndexPath:(NSIndexPath*)indexPath{
    
    BBUserModel * user = [STUserManger defult].loginedUser;
    if (!user) {
        [self.navigationController pushViewController:[BBPhoneLoginViewController new] animated:YES];
        return;
    }
    
    
    BBArticleModel *  model = self.dataSouce[indexPath.section][indexPath.row];
    [BBSystemManger manger].shareNewsID = model.newsID;
    BBHomeTableViewCell * cell = [(id)self.tableView cellForRowAtIndexPath:indexPath];
    BBShareNewsPresentViewController * vc = [BBShareNewsPresentViewController new];
    vc.time = model.dateline;
    vc.news = cell.contenLable.text;
    [vc setShareButtonHandle:^(NSString *title, UIImage *shareImage) {
        TMTabbarViewController * tabvc = (id)[UIApplication sharedApplication].keyWindow.rootViewController;
        [tabvc shareWithChosedTitle:title image:shareImage];
    }];;
    [self presentViewController:vc animated:NO completion:nil];
}
#pragma mark --NetWork Method
- (void)sendWhereRequestWithCity:(NSString*)city{
    if (!city.length) {
        return;
    }
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.requestSerializer.timeoutInterval = 10;
    
    NSString * encodingString = [city stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString * newUrl = @"http://v.juhe.cn/weather/index";
    NSMutableDictionary * parameters  = [NSMutableDictionary new];
    [parameters setObject:@"6a573accfa39494ccde3cdd8ce24a487" forKey:@"key"];
    [parameters setObject:city forKey:@"cityname"];
    newUrl = [NSString stringWithFormat:@"https://www.sojson.com/open/api/weather/json.shtml?city=%@",encodingString];
    [manager GET:newUrl parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        NSDictionary * today = [responseObject[@"data"][@"forecast"] firstObject];

        NSDictionary * dataDic =responseObject[@"data"];
        NSLog(@"%@",dataDic.mj_JSONString);
            BBWheatherModel * model = [BBWheatherModel new];
            NSString * lowTemp = [today[@"low"] description];
             lowTemp = [lowTemp stringByReplacingOccurrencesOfString:@"低温" withString:@""];
            lowTemp = @(lowTemp.intValue).description;
            model.temp = [dataDic[@"wendu"] description];
            model.city = city;
            model.weather = [today[@"type"] description];
        NSString * high = [today[@"high"] description];
        high = [high stringByReplacingOccurrencesOfString:@"高温" withString:@""];
        high = @(high.intValue).description;
        
            model.fb = high;
            model.desFb = dataDic[@"quality"];
            self.header.searchView.weather = model;
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}
- (void)sendGetReadAward{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",severHeader,@"/api/user/readAward"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypeGet
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 
                                             }];
}

@end


